package com.thirtydays.frame.ui.recycle

import androidx.annotation.ColorInt


/**
 * @author 小垚
 * @创建时间： 2020/12/17
 * @描述：
 **/
class DividerBuilder {
    private var mLeftSideLine: SideLine? = null
    private var mTopSideLine: SideLine? = null
    private var mRightSideLine: SideLine? = null
    private var mBottomSideLine: SideLine? = null


    fun setLeftSideLine(isHave: Boolean, @ColorInt color: Int, widthDp: Float, startPaddingDp: Float, endPaddingDp: Float): DividerBuilder? {
        mLeftSideLine = SideLine(isHave, color, widthDp, startPaddingDp, endPaddingDp)
        return this
    }

    fun setTopSideLine(isHave: Boolean, @ColorInt color: Int, widthDp: Float, startPaddingDp: Float, endPaddingDp: Float): DividerBuilder? {
        mTopSideLine = SideLine(isHave, color, widthDp, startPaddingDp, endPaddingDp)
        return this
    }

    fun setRightSideLine(isHave: Boolean, @ColorInt color: Int, widthDp: Float, startPaddingDp: Float, endPaddingDp: Float): DividerBuilder? {
        mRightSideLine = SideLine(isHave, color, widthDp, startPaddingDp, endPaddingDp)
        return this
    }

    fun setBottomSideLine(isHave: Boolean, @ColorInt color: Int, widthDp: Float, startPaddingDp: Float, endPaddingDp: Float): DividerBuilder? {
        mBottomSideLine = SideLine(isHave, color, widthDp, startPaddingDp, endPaddingDp)
        return this
    }

    fun create(): Divider {
        //提供一个默认不显示的sideline，防止空指针
        val defaultSideLine = SideLine(false, -0x99999a, 0f, 0f, 0f)
        mLeftSideLine = if (mLeftSideLine != null) mLeftSideLine else defaultSideLine
        mTopSideLine = if (mTopSideLine != null) mTopSideLine else defaultSideLine
        mRightSideLine = if (mRightSideLine != null) mRightSideLine else defaultSideLine
        mBottomSideLine = if (mBottomSideLine != null) mBottomSideLine else defaultSideLine
        return Divider(mLeftSideLine, mTopSideLine, mRightSideLine, mBottomSideLine)
    }
}